home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11064 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: mayne.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.sources.wanted,comp.lang.c,comp.unix.programmer
  4. Subject: Re: Seek unix2dos.c OR help with tr
  5. Date: 21 Mar 1996 11:53:33 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4isc3tINNifd@mayne.ugrad.cs.ubc.ca>
  8. References: <danpop.826917054@rscernix> <4is3c3$jmp@ns.broadvision.com>
  9. NNTP-Posting-Host: mayne.ugrad.cs.ubc.ca
  10.  
  11. In article <4is3c3$jmp@ns.broadvision.com>,
  12. Patrick Horgan <patrick@broadvision.com> wrote:
  13.  >In article <danpop.826917054@rscernix>, danpop@mail.cern.ch (Dan Pop) writes:
  14.  >>Moreover, 0x1f is not a magic number _in this context_ any more than 2
  15.  >>is a magic number in a binary search algorithm or 3.1415926 is a magic
  16.  >>number when computing the circumference of a circle.  All of them are
  17.  >>natural constants
  18.  >
  19.  >I agree...and it's the way I would do it as well.
  20.  >
  21.  >>
  22.  >>As for Kazimir's example, a "better" definition would be:
  23.  >>
  24.  >>#define CTRL(C) ((C) - 'A' + 1)
  25.  >
  26.  >If I went down this path I'd choose ((C) - '@' )...somehow the + 1 seems as if it
  27.  >will lead to further silly misunderstandings by junior programmers...I much prefer
  28.  >anding off the upper bits though...anding with 0x3f is better and even works for 
  29.  >characters generated on some keyboards whose code is over 127...the subtraction
  30.  >method won't.
  31.  
  32. Oops. I messed up on that one. What I actually use is  ``- 64''. In my zeal to
  33. conceal my use of a magic constant from a thread which condemns their use, I
  34. messed up! :)
  35.  
  36. Here is what I actually have in one header file:
  37.  
  38. #define CTRL(X) ((X)-64)
  39.  
  40. Shame on me! :)
  41.  
  42. I'd only use such a thing if I was certain that there is a necessary dependency
  43. in the program on the ascii character set. In this case, the program in
  44. question used the curses library, and I wanted to check for particular
  45. control keys, which I bound to various commands.
  46. -- 
  47.  
  48.